/**
 * Created by Peter on 2016/4/25.
 */

define(['jquery', 'model/global', 'appLocalStorage'], function ($, global, appLocalStorage) {

    var components = {
        ul_navbar: $('#ul_navbar'),
        ul_leftnav: $('#ul_leftnav')
    };
    return {
        initTopMenuBar: function () {
            var url = location.hash.replace(/^#/, '');
            //BEGIN: IE11 Work Around
            if (!url) {
                try {
                    var documentUrl = window.document.URL;
                    if (documentUrl) {
                        if (documentUrl.indexOf('#', 0) > 0 && documentUrl.indexOf('#', 0) < (documentUrl.length + 1)) {
                            url = documentUrl.substring(documentUrl.indexOf('#', 0) + 1);
                        }
                    }
                } catch (err) {
                }
            }
            //END: IE11 Work Around
            components.ul_navbar.find('li.active').removeClass('active');

            components.ul_navbar.find('li > a').each(function (i, obj) {
                if ("#"+url == $(obj).attr('href')) {
                    $(obj).parent('li').addClass('active');
                }
            });

            components.ul_navbar.find('li').on('click', function (e) {
                components.ul_navbar.find('li.active').removeClass('active');
                $(this).addClass('active');
            });
        }
    }
});
